package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectsMapper;
import com.zzyl.service.NursingProjectsService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NursingProjectsServiceImpl implements NursingProjectsService {

    @Autowired
    private NursingProjectsMapper nursingProjectsMapper;

    @Override
    public PageResponse<NursingProjectVo> queryPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingProjectVo> page =  nursingProjectsMapper.select(name,status);
        PageResponse<NursingProjectVo> pageResponse = new PageResponse<>(page);
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    @Override
    public void add(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectsMapper.insert(nursingProject);
    }

    @Override
    public NursingProjectVo findById(Long id) {
         NursingProjectVo nursingProjectVo = nursingProjectsMapper.findById(id);
         return nursingProjectVo;
    }

    @Override
    public void update(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectsMapper.update(nursingProject);
    }
}
